home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
326-350
/
disk_332
/
kryptor
/
kryptor.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-06
|
2KB
|
105 lines
#define INTUITIONPRIVATE 1
#include <exec/exec.h>
#include <intuition/intuitionbase.h>
#include <functions.h>
#include <libraries/dosextens.h>
#include <libraries/reqbase.h>
struct ReqBase *ReqBase;
struct FileRequester MyFileReqStruct;
char filename[FCHARS+1],
directoryname[DSIZE+1],
answerarray[DSIZE+FCHARS+1];
Anfang()
{
if((ReqBase = (struct ReqBase *)OpenLibrary("req.library", NULL)) == NULL)
exit(20);
directoryname[0] = filename[0] = answerarray[0] = 0;
MyFileReqStruct.PathName = answerarray;
MyFileReqStruct.Dir = directoryname;
MyFileReqStruct.File = filename;
MyFileReqStruct.dirnamescolor = 2;
MyFileReqStruct.devicenamescolor = 2;
MyFileReqStruct.Show[0] = 0;
MyFileReqStruct.Flags = FRQCACHINGM+FRQINFOGADGETM+FRQLOADINGM;
MyFileReqStruct.Title = "Welche Datei ver-/entschlüsseln?";
}
Ende()
{
CloseLibrary(ReqBase);
exit(0);
}
long FileSize(name)
char *name;
{ struct FileLock *fl = NULL;
struct FileInfoBlock *fib;
long size = 0L;
if(fib = AllocMem((long)sizeof(struct FileInfoBlock), MEMF_PUBLIC+MEMF_CLEAR))
{ if(fl = Lock(name, ACCESS_READ))
{ if(Examine(fl, fib))
size = fib->fib_Size;
UnLock(fl);
}
FreeMem(fib, (long)sizeof(struct FileInfoBlock));
}
return size;
}
main()
{ char *text, passwort[32];
struct FileHandle *fp;
long j, k, size;
int pwsize;
Anfang();
setmem(passwort, 32, 0);
do
{ text = size = NULL;
if(FileRequester(&MyFileReqStruct))
{ if(fp = Open(answerarray, MODE_OLDFILE))
{ size = FileSize(answerarray);
if(text = AllocMem(size, MEMF_PUBLIC+MEMF_CLEAR ))
Read(fp, text, size);
else
SimpleRequest("Zu wenig freier Speicher.");
Close(fp);
}
else
SimpleRequest("Ich kann %s nicht öffnen.", answerarray);
}
else Ende(); /* Cancel im FR beendet Programm */
if(text)
{ if(GetString(passwort, "Welches Paßwort?", NULL, 32L, 32L))
{ if(pwsize = strlen(passwort))
{ for(j=0L, k=0L; j<size; j++)
{ text[j] ^= passwort[k];
if(++k > pwsize) k = 0L;
}
if(fp = Open(answerarray, MODE_NEWFILE))
{ Write(fp, text, size);
Close(fp);
SimpleRequest("Datei %s wurde mit\nPaßwort %s behandelt.",
answerarray, passwort);
}
else
SimpleRequest("Ich kann %s nicht überschreiben.", answerarray);
}
}
FreeMem(text, size);
}
} while(1);
}